#include "StdAfx.h"
#include "SerialComm.h"
#include <atlbase.h>

SerialComm::SerialComm(void)
{
}

SerialComm::~SerialComm(void)
{
}

INT_PTR SerialComm::GetSerialCommList(CStringArray &arrSerailCommList)
{
	CRegKey reg;
	DWORD	dRet;
	DWORD	dIndex = 0L;
	TCHAR	szName[256], szValue[256];
	DWORD	dNameLength, dValueLength, dType;

	dRet = reg.Open(HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM", KEY_READ);
	if (dRet != ERROR_SUCCESS)
	{
		return 0;
	}

	while (true)
	{
		dNameLength = dValueLength = 256;
		dRet = RegEnumValue(reg.m_hKey, dIndex, szName, &dNameLength, NULL, &dType, (byte*)szValue, &dValueLength);
		if (dRet != ERROR_SUCCESS) 
		{
			break;
		}

		if (dType == REG_SZ)
		{
			arrSerailCommList.Add(szValue);
		}

		dIndex++;
	}
	reg.Close();

	return arrSerailCommList.GetCount();
}
